/*
 * Util.cpp
 *
 *  Created on: Apr 18, 2011
 *      Author: duilio
 */

#include "Util.h"

string Util::toString(int x) {
	std::stringstream ss;
	ss << x;
	return ss.str();
}

void Util::findAndReplace(string &source, const string find, string replace) {
	size_t j;
	for (; (j = source.find(find)) != string::npos;) {
		source.replace(j, find.length(), replace);
	}
}

string Util::getAsciiTime() {
	time_t rawtime;
	time(&rawtime);
	struct tm * timeinfo = localtime(&rawtime);
	string time = asctime(timeinfo);
	Util::findAndReplace(time, "\n\0", ": ");
	return time;
}

